//
//  RegisterViewController.m
//  DuckAndDoc
//
//  Created by 蓝水软件 on 2017/5/14.
//  Copyright © 2017年 苏州蓝水有限公司. All rights reserved.
//

#import "RegisterViewController.h"

#define BackImageName [UIImage imageNamed:@"login_back"]

@interface RegisterViewController ()
@property (strong, nonatomic) IBOutlet UITextField *userName;
@property (strong, nonatomic) IBOutlet UIImageView *backImage;
@property (strong, nonatomic) IBOutlet UITextField *passWord;
//@property (nonatomic, strong) UIImageView *backImage;   //背景图片
@property (strong, nonatomic) IBOutlet UIButton *registerButton;
@end

@implementation RegisterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUI];
}

- (void)setUI{
    self.backImage.image = [BackImageName imageByBlurDark];
    [self.registerButton addTarget:self action:@selector(doRegister) forControlEvents:UIControlEventTouchUpInside];
}

#pragma mark -- buttonAction
- (void)doRegister{
    if (_userName.text.length == 0) {
        [QXToast showTopWithText:@"用户名不能为空!"];
        [[LxxPlaySound sharePlaySound] play];
        return;
    }
    if (_passWord.text.length == 0) {
        [[LxxPlaySound sharePlaySound] play];
        [QXToast showTopWithText:@"密码不能为空!"];
        return;
    }
    if (_passWord.text.length < 6) {
        [[LxxPlaySound sharePlaySound] play];
        [QXToast showTopWithText:@"密码长度不能小于6位数!"];
        return;
    }
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [QXApi RegisterInbackgroundWithUserName:self.userName.text passWork:self.passWord.text block:^(BOOL isSuccessful, NSError *error) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        if (error) {
            [[LxxPlaySound sharePlaySound] play];
            [QXToast showTopWithText:[[error.userInfo allValues] firstObject]];
        }else{
            [QXToast showTopWithText:LocalizedStrFrom(@"RegisterSuccessOfChina")];
            //调到登录
            [self pushToLogin];
        }
    }];
}

//调到登录
- (void)pushToLogin{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"pushToLogin"
                                                        object:nil];
}

#pragma mark -- 懒加载

@end
